package cn.dengta.webapp.trade.form;

import cn.dengta.webapp.base.form.BaseForm;
import cn.dengta.webapp.trade.entity.UserCoinLog;
import cn.dengta.webapp.trade.model.TradeType;
import cn.dengta.webapp.user.entity.User;
import cn.dengta.webapp.user.model.Gender;
import lombok.*;
import lombok.experimental.Accessors;
import me.codeplayer.util.X;

@Setter
@Getter
@Accessors(chain = true)
public class UserCoinLogQuery extends BaseForm<UserCoinLog> {

	/** 用户ID */
	protected Long userId;
	/** 用户昵称 */
	protected String userNickname;
	/** to用户ID */
	protected Long toUserId;
	/** 性别 */
	protected Gender userGender;
	/** 资金流向：1=收入；0=不变；-1=支出 */
	protected Integer flow;
	/** 交易方：1=from；2=to */
	protected Integer side;
	/** 业务类型 */
	protected String tradeType;
	protected Long[] agentIds;
	@Setter(AccessLevel.NONE)
	public String groupKey;
	@Setter(AccessLevel.NONE)
	public String groupAttr;
	@Setter(AccessLevel.NONE)
	public String selectKey;
	/** 用户ids */
	@Setter(AccessLevel.NONE)
	public Long[] userIds;
	/** 多个类型 */
	@Setter(AccessLevel.NONE)
	public TradeType[] tradeTypes;
	@Setter(AccessLevel.NONE)
	public User user;

	public void setUserId(Long userId) {
		this.userId = userId;
		user().setId(userId);
	}

	public void setUserNickname(String userNickname) {
		this.userNickname = userNickname;
		user().setNickname(userNickname);
	}

	public void setUserGender(Integer userGender) {
		final Gender gender = Gender.of(userGender);
		this.userGender = gender;
		user().setGender(gender);
	}

	private User user() {
		return user = X.getElse(user, User::new);
	}

}
